package com.gfdd.tea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gfdd.tea.dto.TeasDto;
import com.gfdd.tea.mapper.TeasMapper;
import com.gfdd.tea.pojo.Assess;
import com.gfdd.tea.pojo.Teas;
import com.gfdd.tea.service.AssessService;
import com.gfdd.tea.service.TeasService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("teasService")
public class TeasServiceImpl extends ServiceImpl<TeasMapper, Teas> implements TeasService {
    @Autowired
    private AssessService assessService;
    @Override
    public TeasDto queryTeasWithAssess(Long id) {
        Teas tea = this.getById(id);
        TeasDto teasDto=new TeasDto();
        BeanUtils.copyProperties(tea,teasDto);
        LambdaQueryWrapper<Assess> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Assess::getTeaId,id).orderByDesc(Assess::getCreateTime);
        List<Assess> assessList = assessService.list(wrapper);
        teasDto.setAssesses(assessList);
        return teasDto;
    }
}
